//
//  AppointmentOrderViewController.m
//  one_mile_01
//
//  Created by 王雅蓉 on 15/8/26.
//  Copyright (c) 2015年 王雅蓉. All rights reserved.
//

#import "AppointmentOrderViewController.h"
#import "UserInfoModel.h"
#import "Order.h"
#import "DataSigner.h"
#import "RSADataSigner.h"
#import <AlipaySDK/AlipaySDK.h>
#import "QueryProduct.h"

@interface AppointmentOrderViewController ()<UIAlertViewDelegate>

@property (nonatomic, strong) QuerryInfoView *querryInfoV;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UITextView *textView2;
@property (nonatomic, strong) UITextField *textFiled;
@property (nonatomic, strong) UITextView *timeContent;

@property (nonatomic, strong) UserInfoModel *queryInfo;
@property (nonatomic, strong) QueryProduct *product;

@property (nonatomic, strong) UILabel *label12; //小数1
@property (nonatomic, strong) UILabel *label13; //1号蓝线
@property (nonatomic, strong) UILabel *label14; //申请问题
@property (nonatomic, strong) UILabel *label15; //小数2
@property (nonatomic, strong) UILabel *label16; //2号蓝线
@property (nonatomic, strong) UILabel *label18; //小数3
@end

@implementation AppointmentOrderViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        
        self.queryInfo = [[UserInfoModel alloc] init];
        self.product = [[QueryProduct alloc] init];
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = BACKGROUND_ASSISTANT_COLOR;
    
    UIView *navigationV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, NAVIGATIONHEIGHT)];
    navigationV.backgroundColor = BACKGROUND_MAIN_COLOR;
    [self.view addSubview:navigationV];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:NAVIGATION_TITLE_FRAME];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = NAVIGATION_TITLE_FONT;
    titleLabel.text = @"预约";
    [self.view addSubview:titleLabel];
    
    //    返回按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = POP_FRAME;
    [button setBackgroundImage:[UIImage imageNamed:@"pop_light@2x.png"] forState:UIControlStateNormal];
    button.backgroundColor = [UIColor clearColor];
    [button addTarget:self action:@selector(backbutton:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:button];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(button.frame.origin.x, button.frame.origin.y + button.frame.size.height + 30 * FITRATE, WIDTH - button.frame.origin.x * 2, 40 * FITRATE)];
    view.backgroundColor = FONT_ASSISTANT_COLOR;
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 20 * FITRATE;
    [self.view addSubview:view];
    
    //预约标题
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(button.frame.origin.x, view.frame.origin.y, view.frame.size.width - 85 * FITRATE, 40 * FITRATE)];
    label2.text = [NSString stringWithFormat:@" %@", self.appointTopic];
    label2.font = [UIFont systemFontOfSize:15 * FITRATE];
    label2.textColor = [UIColor whiteColor];
    label2.layer.masksToBounds = YES;
    label2.layer.cornerRadius = 20 * FITRATE;
    [self.view addSubview:label2];

    //    200元/次
    self.label3 = [[UILabel alloc]initWithFrame:CGRectMake(view.frame.size.width - 80 * FITRATE, 3 * FITRATE, 80 * FITRATE,15 * FITRATE)];
    _label3.text = self.pricePertimes;
    _label3.font = [UIFont systemFontOfSize:13 * FITRATE];
    _label3.textColor = [UIColor whiteColor];
    [view addSubview:_label3];
    
    //    约2小时
    UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(view.frame.size.width - 80 * FITRATE,_label3.frame.origin.y + _label3.frame.size.height, 80 * FITRATE, 20 * FITRATE)];
    label4.text = @"  约2小时";
    label4.font = [UIFont systemFontOfSize:11 * FITRATE];
    label4.textColor = [UIColor whiteColor];
    [view addSubview:label4];
    
//    滚动
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.frame = CGRectMake(0, label2.frame.origin.y + label2.frame.size.height + 10 * FITRATE, self.view.frame.size.width , 370 * FITRATE);
    self.scrollView.contentSize = CGSizeMake(WIDTH * 3 , 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.backgroundColor = [UIColor clearColor];
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    
//   请教的问题
    UIImageView *imageView1 = [[UIImageView alloc]init];
    imageView1.frame = CGRectMake(10 * FITRATE, 45 * FITRATE, WIDTH - 20 * FITRATE, self.scrollView.frame.size.height - 45 * FITRATE);
    imageView1.layer.cornerRadius = 10;
    imageView1.image = [UIImage imageNamed:@"appointment_bg.png"];
    imageView1.userInteractionEnabled = YES;
    [self.scrollView addSubview:imageView1];
    
    //告诉我们你要请教的问题?
    UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(0 ,15 * FITRATE, WIDTH, 20 * FITRATE)];
    label5.textAlignment = NSTextAlignmentCenter;
    label5.textColor = FONT_ASSISTANT_COLOR;
    label5.text = @"告诉我们你要请教的问题 (300字之内)";
    label5.font = [UIFont systemFontOfSize:16 * FITRATE];
    [self.scrollView addSubview:label5];
    
//    输入框中的内容
    self.textView = [[UITextView alloc]initWithFrame:CGRectMake(label5.frame.origin.x + 20 * FITRATE, 20 * FITRATE, imageView1.frame.size.width - 40 * FITRATE, imageView1.frame.size.height - 40 * FITRATE)];
//    textFile.backgroundColor = [UIColor yellowColor];
    _textView.layer.borderWidth = 1;
    _textView.layer.borderColor = [UIColor colorWithRed:214 / 255.0 green:214 / 255.0 blue:214 / 255.0 alpha:1.0].CGColor;
    _textView.textColor = [UIColor blackColor];
    _textView.delegate = self;
    [imageView1 addSubview:_textView];
  
    //   介绍自己
    UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(imageView1.frame.origin.x + imageView1.frame.size.width + 20 * FITRATE, 45 * FITRATE, imageView1.frame.size.width, imageView1.frame.size.height)];
    imageView2.layer.cornerRadius = 10;
    imageView2.image = [UIImage imageNamed:@"appointment_bg.png"];
    imageView2.userInteractionEnabled = YES;
    [self.scrollView addSubview:imageView2];
    
    //介绍自己?
    UILabel *label8 = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH ,15 * FITRATE, WIDTH, 20 * FITRATE)];
    label8.text = @"介绍自己(300字之内)";
    label8.textColor = FONT_ASSISTANT_COLOR;
    label8.textAlignment = NSTextAlignmentCenter;
    label8.font = [UIFont systemFontOfSize:18 * FITRATE];
    [self.scrollView addSubview:label8];
    
    //    输入框中的内容
    self.textView2 = [[UITextView alloc]initWithFrame:CGRectMake(20 * FITRATE, 20 * FITRATE, imageView2.frame.size.width - 40 * FITRATE, imageView2.frame.size.height - 40 * FITRATE)];
    _textView2.textColor = [UIColor blackColor];
    _textView2.font = [UIFont systemFontOfSize:13 * FITRATE];
    _textView2.layer.borderWidth = 1 * FITRATE;
    _textView2.layer.borderColor = [UIColor colorWithRed:214 / 255.0 green:214 / 255.0 blue:214 / 255.0 alpha:1.0].CGColor;
    _textView2.delegate = self;
    [imageView2 addSubview:_textView2];
    
    //   预约时间表
    self.imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(imageView2.frame.origin.x + imageView2.frame.size.width + 20 * FITRATE, 70 * FITRATE, imageView2.frame.size.width, imageView2.frame.size.height - 25 * FITRATE)];
    self.imageView3.layer.cornerRadius = 10 * FITRATE;
    self.imageView3.image = [UIImage imageNamed:@"appointment_bg.png"];
    self.imageView3.userInteractionEnabled = YES;
    [self.scrollView addSubview:self.imageView3];
    
    //    导师预约时间表
    UILabel *label11 = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH * 2, 20 * FITRATE, WIDTH, 20 * FITRATE)];
    label11.text = @"导师预约时间";
    label11.textAlignment = NSTextAlignmentCenter;
    label11.font = [UIFont systemFontOfSize:18 * FITRATE];
    label11.textColor = FONT_ASSISTANT_COLOR;
    [self.scrollView addSubview:label11];
    
    //    导师预约时间表
    UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH * 2, label11.frame.origin.y + label11.frame.size.height + 10 * FITRATE, WIDTH, 20 * FITRATE)];
    timeLabel.text = @"(请以北京时间为准)";
    timeLabel.textAlignment = NSTextAlignmentCenter;
    timeLabel.font = [UIFont systemFontOfSize:10 * FITRATE];
    timeLabel.textColor = FONT_ASSISTANT_COLOR;
    [self.scrollView addSubview:timeLabel];
    
//    文字描述
    self.timeContent = [[UITextView alloc]initWithFrame:CGRectMake(20 * FITRATE, 20 * FITRATE, self.imageView3.frame.size.width - 40 * FITRATE, self.imageView3.frame.size.height - self.textFiled.frame.origin.y - self.textFiled.frame.size.height - 40 * FITRATE)];
    self.timeContent.text = @"什么时间都方便";
    _timeContent.backgroundColor = [UIColor clearColor];
    _timeContent.layer.borderWidth = 1;
    _timeContent.layer.borderColor = [UIColor colorWithRed:214 / 255.0 green:214 / 255.0 blue:214 / 255.0 alpha:1.0].CGColor;
    _timeContent.delegate = self;
    [self.imageView3 addSubview:_timeContent];

//    小数字
    self.label12 = [[UILabel alloc]initWithFrame:CGRectMake(self.scrollView.frame.origin.x + 70 * FITRATE , self.scrollView.frame.origin.y + self.scrollView.frame.size.height + 10 * FITRATE, 15 * FITRATE, 15 * FITRATE)];
    _label12.layer.masksToBounds = YES;
    _label12.layer.cornerRadius = 7 * FITRATE;
    _label12.text = @"1";
    _label12.textColor = [UIColor whiteColor];
    _label12.font = [UIFont systemFontOfSize:10 * FITRATE];
    _label12.textAlignment = NSTextAlignmentCenter;
    _label12.backgroundColor = FONT_ASSISTANT_COLOR;
    [self.view addSubview:_label12];
    //蓝线
    self.label13 = [[UILabel alloc]initWithFrame:CGRectMake(_label12.frame.origin.x + _label12.frame.size.width, _label12.frame.origin.y + 7 * FITRATE ,(WIDTH - 140 * FITRATE - 45) / 2, 1 * FITRATE)];
    self.label13.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:_label13];
    
    UILabel *label14 = [[UILabel alloc]initWithFrame:CGRectMake(_label12.frame.origin.x - 12 * FITRATE, _label12.frame.origin.y + _label12.frame.size.height, 80 * FITRATE, 20 * FITRATE)];
    label14.backgroundColor = [UIColor clearColor];
    label14.text =@"申请问题";
    label14.font = [UIFont systemFontOfSize:10 * FITRATE];
    [self.view addSubview:label14];
        
//    导师确认
    //    小数字
    self.label15 = [[UILabel alloc]initWithFrame:CGRectMake(_label13.frame.origin.x + _label13.frame.size.width ,_label12.frame.origin.y,self.label12.frame.size.width, self.label12.frame.size.height)];
    _label15.layer.masksToBounds = YES;
    _label15.layer.cornerRadius = 7 * FITRATE;
    _label15.text = @"2";
    _label15.font = [UIFont systemFontOfSize:10 * FITRATE];
    _label15.textAlignment = NSTextAlignmentCenter;
    _label15.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:_label15];
    //蓝线
    _label16 = [[UILabel alloc]initWithFrame:CGRectMake(_label15.frame.origin.x + _label15.frame.size.width, _label15.frame.origin.y + 7 * FITRATE ,_label13.frame.size.width, 1 * FITRATE)];
    _label16.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:_label16];
    
    UILabel *label17 = [[UILabel alloc]initWithFrame:CGRectMake(_label15.frame.origin.x - 12 * FITRATE, _label15.frame.origin.y + _label15.frame.size.height, 80 * FITRATE, 20 * FITRATE)];
    label17.backgroundColor = [UIColor clearColor];
    label17.text =@"自我介绍";
    label17.font = [UIFont systemFontOfSize:10 * FITRATE];
    [self.view addSubview:label17];
    
    //    协商时间
    //    小数字
    self.label18 = [[UILabel alloc]initWithFrame:CGRectMake(_label16.frame.origin.x + _label16.frame.size.width ,_label12.frame.origin.y,self.label15.frame.size.width, self.label15.frame.size.height)];
    _label18.layer.masksToBounds = YES;
    _label18.layer.cornerRadius = 7 * FITRATE;
    _label18.text = @"3";
    _label18.font = [UIFont systemFontOfSize:10 * FITRATE];
    _label18.textAlignment = NSTextAlignmentCenter;
    _label18.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:_label18];
    
    UILabel *label20 = [[UILabel alloc]initWithFrame:CGRectMake(_label18.frame.origin.x - 12 * FITRATE, _label18.frame.origin.y + _label18.frame.size.height, 80 * FITRATE, 20 * FITRATE)];
    label20.backgroundColor = [UIColor clearColor];
    label20.text =@"预约时间";
    label20.font = [UIFont systemFontOfSize:10 * FITRATE];
    [self.view addSubview:label20];

    UILabel *label27 = [[UILabel alloc]initWithFrame:CGRectMake(button.frame.origin.x, label20.frame.origin.y + label20.frame.size.height + 10 * FITRATE, WIDTH - button.frame.origin.x * 2, 35 * FITRATE)];
    label27.backgroundColor = [UIColor clearColor];
    label27.layer.masksToBounds = YES;
    label27.layer.cornerRadius = 17 * FITRATE;
    //边框宽度
    label27.layer.borderWidth = 1 * FITRATE;
    //边框颜色
    label27.layer.borderColor = [UIColor colorWithRed:71 / 255.0 green:56 / 255.0 blue:57 / 255.0 alpha:0.6].CGColor;
    [self.view addSubview:label27];
    
    
//    警示图片
    UIImageView *imageView4 = [[UIImageView alloc]initWithFrame:CGRectMake(10 * FITRATE, 4 * FITRATE, 25 * FITRATE, 25 * FITRATE)];
    imageView4.image = [UIImage imageNamed:@"tutorAppointmentAttention"];
    [label27 addSubview:imageView4];
    
//    详细描述
    UILabel *label28 = [[UILabel alloc]initWithFrame:CGRectMake(imageView4.frame.origin.x + imageView4.frame.size.width + 10 * FITRATE, imageView4.frame.origin.y, label27.frame.size.width - imageView4.frame.size.width - imageView4.frame.origin.x - 20 * FITRATE, 13 * FITRATE)];
    label28.text = @"详细描述有助于导师针对你的情况咨询做准备";
    label28.font = [UIFont systemFontOfSize:9 * FITRATE];
    label28.textColor = [UIColor colorWithRed:172/255.0 green:172/255.0 blue:172/255.0 alpha:1.0];
    [label27 addSubview:label28];
    
    //    详细描述
    UILabel *label29 = [[UILabel alloc]initWithFrame:CGRectMake(label28.frame.origin.x, label28.frame.origin.y + label28.frame.size.height,label27.frame.size.width - imageView4.frame.size.width - imageView4.frame.origin.x - 20 * FITRATE, 15 * FITRATE)];
    label29.text = @"您填写的一英里资料只有一英里可以看到,不会泄露给其他人";
    label29.font = [UIFont systemFontOfSize:8 * FITRATE];
    label29.textColor = [UIColor colorWithRed:228/255.0 green:172/255.0 blue:190/255.0 alpha:1.0];
    [label27 addSubview:label29];
    
//    提交
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(0, HEIGHT - 50 * FITRATE, WIDTH, 50 * FITRATE)];
    button2.backgroundColor = FONT_ASSISTANT_COLOR;
    [button2 setTitle:@"提交" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(submitForAppointAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    
    self.querryInfoV = [[QuerryInfoView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, HEIGHT)];
    _querryInfoV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.9f];
    _querryInfoV.myDelegate = self;
    [self.view addSubview:_querryInfoV];
    
    
    UIGestureRecognizer *resignKeyboard = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTapped:)];
    [self.view addGestureRecognizer:resignKeyboard];

    // Do any additional setup after loading the view.
    [self getDetailUserInfo];
    [self getIntroduction];
}


#pragma mark -- textFieldDelegate
-(void)textViewDidBeginEditing:(UITextView *)textView
{
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:0.3f];
    self.view.frame = CGRectMake(0, -90 * FITRATE, WIDTH, HEIGHT);
    
    [UIView commitAnimations];
}


-(void)textViewDidEndEditing:(UITextView *)textView
{
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:0.3f];
    
    self.view.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
    
    [UIView commitAnimations];
}


//撤销键盘
-(void)backgroundTapped:(UITapGestureRecognizer *)tap
{
    [self.view endEditing:YES];
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x > 300 && scrollView.contentOffset.x < WIDTH * 2 - 100) {

        [self.scrollView setContentOffset:CGPointMake(WIDTH , 0) animated:YES];
        _label15.backgroundColor = FONT_ASSISTANT_COLOR;
        _label15.textColor = [UIColor whiteColor];
        _label13.backgroundColor = FONT_ASSISTANT_COLOR;
        _label12.backgroundColor = [UIColor lightGrayColor];
        _label12.textColor = [UIColor blackColor];
        _label18.backgroundColor = [UIColor lightGrayColor];
        _label18.textColor = [UIColor blackColor];
        _label16.backgroundColor = [UIColor lightGrayColor];

    }else if (scrollView.contentOffset.x < 300 ) {
        
        [self.scrollView setContentOffset:CGPointMake(0 , 0) animated:YES];
        _label12.backgroundColor = FONT_ASSISTANT_COLOR;
        _label12.textColor = [UIColor whiteColor];
        _label18.backgroundColor = [UIColor lightGrayColor];
        _label18.textColor = [UIColor blackColor];
        _label16.backgroundColor = [UIColor lightGrayColor];
        _label15.backgroundColor = [UIColor lightGrayColor];
        _label15.textColor = [UIColor blackColor];
        _label13.backgroundColor = [UIColor lightGrayColor];

    }else{
        
        [self.scrollView setContentOffset:CGPointMake(WIDTH * 2, 0) animated:YES];
        
        _label18.backgroundColor = FONT_ASSISTANT_COLOR;
        _label18.textColor = [UIColor whiteColor];
        _label16.backgroundColor =FONT_ASSISTANT_COLOR;
        _label12.backgroundColor = [UIColor lightGrayColor];
        _label12.textColor = [UIColor blackColor];
        _label15.backgroundColor = [UIColor lightGrayColor];
        _label15.textColor = [UIColor blackColor];
        _label13.backgroundColor = [UIColor lightGrayColor];

    }
}

-(void)submitForAppointAction:(UIButton *)button
{
    if (_textView.text.length == 0 || _textView.text.length > 300 || _textView2.text.length == 0 || _textView2.text.length > 300) {
        
        if (_textView.text.length == 0) {
            [self showWrongOrderDetail:@"请教的问题不能为空"];
        } else if (_textView.text.length > 300) {
            [self showWrongOrderDetail:@"请教的问题不得超过300字"];
        } else if (_textView2.text.length == 0) {
            [self showWrongOrderDetail:@"介绍自己不能为空"];
        } else if (_textView2.text.length > 300) {
            [self showWrongOrderDetail:@"介绍自己不得超过300字"];
        }
    } else {
        [UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
            
            self.querryInfoV.frame = CGRectMake(0, 0, WIDTH, HEIGHT);
        } completion:^(BOOL finished) {
            
        }];
    }
}

-(void)showWrongOrderDetail:(NSString *)msg
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}

#pragma mark -- 取消和付款
-(void)cancelToBack
{
    [UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        
        self.querryInfoV.frame = CGRectMake(0, HEIGHT, WIDTH, HEIGHT);
    } completion:^(BOOL finished) {
        
        [self.view endEditing:YES];
    }];
}

-(void)querryToPay:(NSString *)clientName withPhone:(NSString *)phone withChat:(NSString *)chat withEmail:(NSString *)email
{
    if (clientName.length == 0) {
        
        [self showWrongOrderDetail:@"不要害羞，大方地告诉我们您的真实姓名"];
        return;
    } else {
        _queryInfo.name = clientName;
    }
    
    if (phone.length == 0) {
        
        [self showWrongOrderDetail:@"不要害羞，大方地告诉我们您的手机号码"];
        return;
    } else {
        _queryInfo.phone = phone;
    }
    
    if (chat.length == 0) {
        [self showWrongOrderDetail:@"不要害羞，大方地告诉我们您的微信号"];
        return;
    } else {
        _queryInfo.wechatNo = chat;
    }
    
    if (email.length == 0) {
        
        [self showWrongOrderDetail:@"不要害羞，大方地告诉我们您的邮箱"];
        
        return;
    } else {
        _queryInfo.email = email;
    }
    
    [UIView animateWithDuration:0.4 delay:0.1 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        
        self.querryInfoV.frame = CGRectMake(0, HEIGHT, WIDTH, HEIGHT);
        [self getCreateOrder];
    } completion:^(BOOL finished) {
        
    }];
}

-(void)backbutton:(UIButton *)button{

    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -- 获取数据
//获取个人自我介绍
-(void)getIntroduction
{
    [AFNConnect AFNConnectWithUrl:HTTPREQUEST withBodyData:[AFNConnect createDataForIntro:[[[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"] objectForKey:@"uid"]] connectBlock:^(id data) {
        
        NSDictionary *dic = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        if ([[dic objectForKey:@"state"] isEqualToString:@"success"]) {
            
            if (((NSString *)[dic objectForKey:@"introduce"]).length == 0) {
                
            } else {
            
                _textView2.text = [dic objectForKey:@"introduce"];
            }
        }
    }];
}

//获取个人详细信息
-(void)getDetailUserInfo
{
    [AFNConnect AFNConnectWithUrl:HTTPREQUEST withBodyData:[AFNConnect createDataForPersonalInfo:[[[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"] objectForKey:@"uid"]] connectBlock:^(id data) {
        
        NSDictionary *dic = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        self.queryInfo.resume = [dic objectForKey:@"resume"];
        self.queryInfo.phone = [dic objectForKey:@"phone"];
        self.queryInfo.email = [dic objectForKey:@"email"];
        self.queryInfo.nickName = [dic objectForKey:@"nickName"];
        self.queryInfo.address = [dic objectForKey:@"address"];
        self.queryInfo.name = [dic objectForKey:@"name"];
        
        self.querryInfoV.userQueryM = self.queryInfo;
    }];
}

#pragma mark  =======
//创建订单
-(void)getCreateOrder
{
//    if (_textView.text.length == 0 || _textView2.text.length == 0 || _timeContent.text.length == 0) {
//        
//        UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"提示" message:@"不能为空，请认真填写" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        [alertV show];
//    } else {
        [AFNConnect AFNConnectWithUrl:HTTPREQUEST withBodyData:[AFNConnect createDataForCreateOrder:[[[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"] objectForKey:@"uid"] withQuestion:_textView.text withIntro:_textView2.text withTeacherID:self.teacherIDForOrder withSelectTime:self.timeContent.text withName:_queryInfo.name withPhone:_queryInfo.phone withEmail:_queryInfo.email withContact:_queryInfo.wechatNo] connectBlock:^(id data) {
            
            NSDictionary *dic = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            if ([[dic objectForKey:@"state"] isEqualToString:@"success"]) {
                
                QuerryInfoViewController *querryInfoVC = [[QuerryInfoViewController alloc] init];
                querryInfoVC.contactWayForQuerry = _contactWay;
                
                [self.navigationController pushViewController:querryInfoVC animated:YES];
            } else {
                
                if ([[dic objectForKey:@"msg"] isEqualToString:@"uid is not existed"]) {
                    
                    [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"isLogin"];
                    [[TagForClient shareTagDataHandle] antiBindAccount:[[[NSUserDefaults standardUserDefaults] objectForKey:@"userInfo"] objectForKey:@"number"]];
                    
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登录超时，请重新登录" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                    [alert show];
                } else if ([[dic objectForKey:@"msg"] isEqualToString:@"teacher is not existed"]){
                
                    [self showWrongOrderDetail:@"导师不存在"];
                } else if ([[dic objectForKey:@"msg"] isEqualToString:@"teacher is not on service"]) {
                    [self showWrongOrderDetail:@"导师当前无法服务"];
                } else if ([[dic objectForKey:@"msg"] isEqualToString:@"BAD PHONE NUMBER OR BAD EMAIL"]) {
                    [self showWrongOrderDetail:@"手机号或者邮箱格式错误"];
                } else {
                    [self showWrongOrderDetail:@"订单填写不完整"];
                }
            }
        }];
//    }
}

#pragma mark -- alertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ([alertView.message isEqualToString:@"登录超时，请重新登录"]) {
        
        if (buttonIndex == 1) {
            
            LoginViewController *loginVC = [[LoginViewController alloc] init];
            
            loginVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            
            [self presentViewController:loginVC animated:YES completion:^{
                
            }];
        }
    }
}

#pragma mark -- viewWillAppear & viewWillDisappear
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.alpha = 0;
//    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.alpha = 1;
//    [self.navigationController setNavigationBarHidden:NO animated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
